package org.chen.mapper.news;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.chen.model.CommentTask;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface CommentTaskMapper extends BaseMapper<CommentTask> {
    @Insert("<script>" +
            "INSERT INTO comment_task (" +
            "id, batch_no, comment_content, nickname, email, website_url, " +
            "target_url, status, retry_count, error_message, new_comment_url, " +
            "create_time, update_time) VALUES " +
            "<foreach collection='tasks' item='task' separator=','>" +
            "(" +
            "#{task.id}, #{task.batchNo}, #{task.commentContent}, " +
            "#{task.nickname}, #{task.email}, #{task.websiteUrl}, " +
            "#{task.targetUrl}, #{task.status}, #{task.retryCount}, " +
            "#{task.errorMessage}, #{task.newCommentUrl}, " +
            "#{task.createTime}, #{task.updateTime}" +
            ")" +
            "</foreach>" +
            "</script>")
    int batchInsert(@Param("tasks") List<CommentTask> tasks);

    /**
     * 通过批次号和目标URL查询
     */
    @Select("SELECT * FROM comment_task " +
            "WHERE batch_no = #{batchNo} " +
            "AND target_url = #{targetUrl} " +
            "LIMIT 1")
    CommentTask selectByBatchNoAndTargetUrl(
            @Param("batchNo") String batchNo,
            @Param("targetUrl") String targetUrl);
}
